package cn.gson.crm.control;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gson.crm.model.pojo.Backplan;
import cn.gson.crm.model.pojo.OrderResult;
import cn.gson.crm.model.pojo.Paymentplan;
import cn.gson.crm.model.vo.BackplanVO;
import cn.gson.crm.model.vo.PaymentPlanVO;
import cn.gson.crm.service.PpService;

@Controller
public class ppControl {
	@Autowired
	private PpService pService;
	
	@GetMapping("/getAllPP")
	@ResponseBody
	public Map getAllPP(int page,int rows) {
		Map map = new HashMap<>();
		Long count = pService.count();
		List<PaymentPlanVO> list = pService.getAllpp(page, rows);
		map.put("total", count);
		map.put("rows", list);
		return map;
	}
	
	@GetMapping("/toPp")
	public String toPp() {
		return "zj/paymentPlan";
	}
	
	@GetMapping("/deletepp")
	@ResponseBody
	public OrderResult deletepp(Long ppId) {
		try {
			pService.deletepp(ppId);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}
	}
	
	@PostMapping("/addPp")
	@ResponseBody
	public OrderResult addPp(Paymentplan bp) {
		try {
			pService.addPaymentPlan(bp);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}
	}
	
	@PostMapping("/editPp")
	@ResponseBody
	public OrderResult editPp(Paymentplan bp,Long ppId) {
		try {
			pService.addPaymentPlan(bp);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}
	}
	
	@GetMapping("/getPpById")
	@ResponseBody
	public PaymentPlanVO getPpById(Long ppId) {
		return pService.getPpById(ppId);
	}
}
